from flask import Flask, render_template, request
from flask_login_multi.login_manager import LoginManager

from config import secure, settings
from models.base import db

login_manager = LoginManager()


def create_app():
    app = Flask(__name__)

    # config
    app.config.from_object(secure)
    app.config.from_object(settings)

    # register blueprint
    from views.front import front as front_bp
    from views.admin import admin as admin_bp
    app.register_blueprint(front_bp)
    app.register_blueprint(admin_bp)

    db.init_app(app)
    db.create_all(app=app)

    login_manager.init_app(app)
    login_manager.login_view = {
        'user': 'front.logoin',
        'admin': 'admin.logoin',
    }
    return app



